import React, { Component } from "react";

export default class App extends Component {
  state = {
    msg: "牛气冲天",
  };
  static getDerivedStateFromProps(props, state) {
    console.log("1、组件更新getDerivedStateFromProps方法");
  }
  shouldComponentUpdate(nextProps, nextState) {
    // false => 组件不会更新
    // true => 组件更新
    console.log("2、组件更新shouldComponentUpdate方法");
    return true;
  }
  dianji = () => {
    this.setState({
      msg: "牛年大吉",
    });
  };
  render() {
    console.log("3、组件更新render方法");

    return (
      <div>
        <h3>{this.state.msg}</h3>
        <button onClick={this.dianji}>变化</button>
      </div>
    );
  }
  getSnapshotBeforeUpdate(nextProps, nextState) {
    console.log("4、组件更新getSnapshotBeforeUpdate方法");
    return null;
  }
  componentDidUpdate(nextPROPS, nextState, snapshot) {
    console.log("5、组件更新componentDidUpdatee方法");
  }
}
